package com.sline.Reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class Demo4_Field {
    public static void main(String[] args) throws Exception {
        Class clazz = Class.forName("com.sline.Reflect.Person");
        Constructor constructor = clazz.getConstructor(String.class, int.class);
        Person person = (Person)constructor.newInstance("张三", 23);

        Field field = clazz.getDeclaredField("name");
        field.setAccessible(true);                          // 去除私有权限
        field.set(person, "李四");
        System.out.println(person);

        Field[] fields = clazz.getFields();
        System.out.println(fields);
    }
}
